<template>
  <div id="app" @click.stop="isDo()">
    <router-view />
    <el-dialog 
    :visible.sync="userLoading"
    :show-close="false"
    :close-on-click-modal="false"
    width="20%"
    title="登录"
    >
      <div style="padding-right: 20px;">
        <div>
          <p>用户名：</p>
          <el-input v-model="login.name"></el-input>
        </div>
        <div>
          <p>密码：</p>
          <el-input type="password" v-model="login.passworld" @change="userlogin"></el-input>
        </div>
        <el-button type="primary" style="width:100%;margin-top:20px" @click="userlogin">登录</el-button>
        <p style="font-size: 14px;color: rgb(131 127 127);text-align: center;margin:0;padding-top:10px">您已长时间未操作，请重新登录！</p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return{
      lastTime: null, //最后一次点击的时间
      currentTime: null, //当前点击的时间
      timeOut: 30*60*1000, //设置超时时间： 30分钟
      // timeOut:10000,
      userLoading:false,
      path:'',
      login: {
        name: "",
        passworld: ""
      },
    }
  },
  methods: {
    isDo() {
        if(this.path.indexOf('home')==-1){
          return false
        }
        this.currentTime = new Date().getTime(); //记录这次点击的时间
        if(this.currentTime - this.lastTime > this.timeOut) { //判断上次最后一次点击的时间和这次点击的时间间隔是否大于10分钟
            // 这里写状态已过期后执行的操作
          if(this.$Cookies.get('chksave',{expires:7,path:"/"})=="true"){
            this.login.name = this.$Cookies.get('loginName',{expires:7,path:"/"})
            this.login.passworld = this.$Cookies.get("password",{expires:7,path:"/"})
          }else{
             this.$Cookies.remove("loginName",{expires:7,path:"/"});
             this.$Cookies.remove("password",{expires:7,path:"/"});
          }
              localStorage.removeItem("USER_ID");
              localStorage.removeItem("TOKEN");
              this.userLoading=true
              // this.$Cookies.set("MASK",false)
        } else {
          this.userLoading=false
          this.lastTime = new Date().getTime(); //如果在10分钟内点击，则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
        }
    },
    userlogin(){
      var that = this;
      localStorage.removeItem("USER_ID");
      localStorage.removeItem("TOKEN");
      that.$.ajax({
      url: that.$API.ajaxPath,
      type: "post",
      data: {
        interfaceName: "antu.newportal-zjx.provider.user.UserProvider",
        methodName: "userLogin",
        args: [
          that.login.name,
          that.$md5(that.login.passworld),
          ""
        ]
      },
      dataType: "json",
      success: res => {
        that.loading = false;
        if (res.status == "0") {
          let userMsg = JSON.parse(res.result);
          let USER_ID = userMsg.EMPLOYEE.EMPLOYEE_ID;
          let TOKEN = userMsg.tokenV2;
          localStorage.setItem("USER_ID", USER_ID);
          this.$Cookies.set("loginName", this.login.name,{expires:7,path:"/"})
          this.$Cookies.set("password", this.login.passworld,{expires:7,path:"/"})
          this.$Cookies.set('REGION_ID',userMsg.ORG.REGION_ID,{expires:7,path:'/'})
          //记住我
          this.$Cookies.set("chksave",this.saveuser,{expires:7,path:"/"})
          localStorage.setItem("TOKEN", TOKEN);
          var timestamp=new Date().getTime();
          location.reload();
          that.userLoading = false
          
          // window.location.href=window.location.href.indexOf('home')>0 ? window.location.href +timestamp >0: window.location.href +'?rmd=' +timestamp;
        } else {
          this.$message({
            message: res.message,
            type: "warning"
          });
        }
      },
      error: xhr => {
        console.log(xhr);
        that.loading = false;
      }
    });
    }

},
created(){
    this.lastTime = new Date().getTime();   //网页第一次打开时，记录当前时间
    this.path = window.location.href;
    // this.$Cookies.set("MASK",false)
    // setInterval(()=>{
    //   if(this.currentTime - this.lastTime > this.timeOut) {
    //     document.getElementById('app').children.css('pointerEvents','nonoe')
    //   }
    // },10000)
}
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}
body::-webkit-scrollbar,.home_dark .el-table__body-wrapper::-webkit-scrollbar {
  /*滚动条整体样式*/
  width : 10px!important;  /*高宽分别对应横竖滚动条的尺寸*/
  height: 1px!important;
  }
body::-webkit-scrollbar-thumb,.home_dark .el-table__body-wrapper::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 10px!important;
  box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
  background   :  #ffffff!important
  }
body::-webkit-scrollbar-track,.home_dark .el-table__body-wrapper::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
  border-radius: 10px!important;
  background   : rgba(37, 43, 90, 0.88)!important;
  }
  .home_light .el-table__body-wrapper::-webkit-scrollbar {
  /*滚动条整体样式*/
  width : 10px!important;  /*高宽分别对应横竖滚动条的尺寸*/
  height: 1px!important;
  }
.home_light .el-table__body-wrapper::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 10px!important;
  box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
  background   :  #409EFF!important;
  }
.home_light .el-table__body-wrapper::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
  border-radius: 10px!important;
  background   : #ffffff!important
  }
  .home_light .pagination-box>li,.home_light .more,.home_light .btn-next,.home_light .btn-prev{
  color: #606266;
}
.home_light .active{
  color: #FFF!important;
}
.home_dark .el-table th, .el-table tr{
    background: rgb(24, 65, 141);
  }
  .tabHie .el-tabs__content{
  height: 100%!important;
}
.home_dark .el-radio__label{
  font-size:18px;
}
.home_dark .is-checked .el-radio__label{
  color:#409EFF
}
.el-dialog__header{
  background: rgb(0, 133, 255);
}
.el-dialog__title{
      font-size: 16px;
    color: #FFF!important;
}
.el-dialog__body{
  padding: 0 0 30px 20px!important;
}
.el-dialog__header{
    padding: 10px 20px 10px;
}
.el-dialog__headerbtn .el-dialog__close{
  color: #FFF!important;
}
.el-radio-button__inner{
  background:#232852;
  border:1px solid #409eff;
  color:#FFF;
  padding:8px 20px
}
/* .home_dark .el-menu{
  background: linear-gradient(180deg, #252b5a, rgba(37, 43, 90, 0) 100%)!important;
  border-right:none
}
.home_dark .el-menu .el-submenu .el-menu{
  background: linear-gradient(180deg, #252b5a, rgba(37, 43, 90, 0) 100%)!important;
}
.home_dark .is-active{
  color:#409eff!important;
}
.home_dark .el-submenu__title{
  color: #FFF;
  font-size: 16px;
} */
</style>
